< previous page page_479 next page >

Page 479
e10a6a0a59f035e870d90cca05b85fce.gif
Dim j As Integer
Dim diffx As Single
Dim diffz As Single
Dim dist2(1 To 4) As Single
Dim wgt As Single
Dim tot As Single
Dim Y As Single

    ' Compute the distance squared to each point.
    For i = 1 To num
        diffx = X - Data(best_i(i)).coord(1)
        diffz = Z - Data(best_i(i)).coord(3)
        dist2(i) = diffx * diffx + diffz * diffz
        If dist2(i) = 0 Then
            Y = Data(best_i(i)).coord(2)
            Exit Function
        End If
    Next i

    ' Compute the contribution due to each point.
    Y = 0
    For i = 1 To num
         ' Compute the weight for point i.
        wgt = 1
        For j = 1 To num
             If j <> i Then
                 wgt = wgt * dist2(j)
             End If
        Next j
        Y = Y + wgt * Data(best_i(i)).coord(2)
        tot = tot + wgt
    Next i

    WeightedAverage = Y / tot
End Function


' Return the index of the nearest point in the
' indicated direction.
Private Function NearestPoint(ByVal X As Single, _
    ByVal Z As Single, ByVal on_left As Boolean, _
    ByVal on_top As Boolean) As Integer
Dim i As Integer
Dim best_i As Integer
Dim best_dist2 As Single
Dim diffx As Single
Dim diffz As Single
Dim dist2 As Single

    ' Start with the first data point.
    best_i = 0
    best_dist2 = 1E+30

 
< previous page page_479 next page >